package co.chonghao.ch_kuaichong_user.ui.fragments;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.amap.api.maps.AMap;
import com.amap.api.maps.MapFragment;
import com.amap.api.maps.MapView;

import butterknife.BindView;
import butterknife.ButterKnife;
import co.chonghao.ch_kuaichong_user.R;

/**
 * Created by admin on 2017/8/1.
 */

public class Stationary_Charging_Fragment extends Fragment {
    @BindView(R.id.map)
    MapView mapView;
    private AMap aMap;
    private static Stationary_Charging_Fragment stationary_charging_fragment = null;
    private View view;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (view == null) {
            view = inflater.inflate(R.layout.fragment_stationary, null);}
            ButterKnife.bind(this, view);
            mapView.onCreate(savedInstanceState);
            if (aMap == null) {
                 aMap = mapView.getMap();
            }
                if (view.getParent() != null) {
                    ((ViewGroup) view.getParent()).removeView(view);
                }


        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        if (mapView != null) {
            mapView.onSaveInstanceState(savedInstanceState);
        }
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
//        ((MainActivity) activity.onSectionAttached();
    }
    @Override
    public void onResume() {
        super.onResume();
        if (mapView != null) {
            mapView.onResume();
        }
    }

    @Override
    public void onStart() {
        super.onStart();
        if (mapView != null) {
            mapView.onPause();
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        if (mapView!=null) {
            mapView.onPause();
        }
    }


    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mapView.onSaveInstanceState(outState);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (mapView!=null) {
            mapView.onDestroy();

        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }


    public static Fragment newInstance() {
        if (stationary_charging_fragment == null) {
            synchronized (MapFragment.class) {
                if (stationary_charging_fragment == null) {
                    stationary_charging_fragment = new Stationary_Charging_Fragment();
                }
            }
        }
        return stationary_charging_fragment;
    }
}
